<html>
<head>
    <title>添加</title>
</head>
<link rel="stylesheet" href="/js/layui/css/layui.css" />
<body>
<form class="layui-form" lay-filter="issue"   action="" >
    <input type="hidden" name="id" id="id">
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-col-xs10">
            <div id="test2" class="demo-transfer"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
</body>

<script src="/js/system.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script src="/js/layui/layui.js"></script>
<script>
    layui.use(['transfer', 'form','layer','jquery'], function(){
    var form=layui.form,
        transfer = layui.transfer,
        layer= layui.layer;
        var $=layui.jquery;
        $("#id").val(getQueryString("id"));
        $.ajax({
            url:'/customer/getList',
            type:"get",
            dataType:"json",
            data:{"id":getQueryString("id")},
            success:function (da) {
                console.log(da);
                //定义标题及数据源
                transfer.render({
                    elem: '#test2'
                    ,id:"issue"
                    ,title: ['未发送用户', '发送用户']  //自定义标题
                    ,data: da
                    //,width: 150 //定义宽度
                    // ,height: 210 //定义高度
                })
            }
        });

        //监听提交 15039939677
        form.on('submit(formDemo)', function(data){
            //获取右侧穿梭框的对象信息
            var getdata= transfer.getData('issue');
            if(getdata.length==0){
                layer.msg("请选择发送用户！");
            }
            //将右侧数据对象，遍历，将用户id拼接到customerIds中，以英文，链接
            var customerIds="";
            $.each(getdata,function(i,rs){
                console.log(rs);
                customerIds+=rs.value+",";
            })
            console.log(customerIds);
            $.ajax({
                url:'/customerCoupon/issue',
                type:"post",
                dataType:"json",
                data:{"id":$("#id").val(),"customerIds":customerIds},
                success:function (da) {
                    if (da.code == 200) {
                        layer.alert(da.msg, function () {
                            // window.parent.location.reload();//刷新父页面
                            // parent.layer.close(layer.index);//关闭弹出层
                            parent.layer.closeAll();
                        });
                    } else {
                        layer.msg(da.msg);
                    }
                }
            });
            return false;
        });

    });

</script>
</html>